package com.zhuzi.dto.weixin.text;

import cn.hutool.core.util.StrUtil;
import com.google.common.collect.Lists;
import com.zhuzi.common.utils.LocalDateTimeUtils;
import com.zhuzi.common.utils.StringUtil;
import com.zhuzi.dto.weixin.WxContent;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.collections4.CollectionUtils;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zhuzi
 * 2023/7/9 10:24
 * 巨潮公告
 */
@Data
@Accessors(chain = true)
public class JcNotionStyle extends WxContent {

    public List<Item> itemList;
    private String title;

    @Override
    public String content() {
        String titles = StringUtil.centerEmoji(title, 20, "\uD83D\uDCE3", "\uD83D\uDCE3");
        ArrayList<String> strings = Lists.newArrayList(titles);
        strings.add(StrUtil.repeat("——", 6));
        if (CollectionUtils.isNotEmpty(itemList)) {
            itemList.forEach(gnItem -> {
                strings.add(gnItem.format());
                strings.add(StrUtil.repeat("——", 6));
            });

        }
        strings.add("采集时间:" + LocalDateTimeUtils.formatNormal());
        return String.join(StrUtil.LF, strings);
    }

    @Data
    @Accessors(chain = true)
    public static class Item {
        public LocalDate pubDate;
        private String secCode;
        private String secName;
        private String annTitle;
        private String adjunctUrl;

        public Item setAdjunctUrl(String adjunctUrl) {
            this.adjunctUrl = "http://static.cninfo.com.cn/" + adjunctUrl;
            return this;
        }

        public String format() {
            return StrUtil.format("[{}-{}]\n{}|{}\n{}\n", secCode, secName, pubDate, annTitle, adjunctUrl);
        }
    }
}
